package com.atguigu.gulimall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author 小明
 * @date 2022/11/13 0013
 * @apiNote
 */
@Configuration
public class GulimallCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration CorsConfiguration = new CorsConfiguration();

        //1.设置跨域
        CorsConfiguration.addAllowedHeader("*");
        CorsConfiguration.addAllowedMethod("*");
        CorsConfiguration.addAllowedOrigin("*");
        CorsConfiguration.setAllowCredentials(true);


        source.registerCorsConfiguration("/**",CorsConfiguration);
        return new  CorsWebFilter(source);
    }
}
